<template>
    <van-picker
      title="更新性别"
      show-toolbar
      :columns="columns"
      @confirm="onConfirm"
      @cancel="onCancel"
      :default-index="sex"
    />
  </template>
  
  <script>
  import { setUserInfoAPI } from '@/api'
  export default {
    props: {
      sex: {
        type: [Number, String],
        required: true
      }
    },
    data() {
      return {
        columns: ['男', '女']
      }
    },
    methods: {
      async onConfirm(value, index) {
        await setUserInfoAPI({
          gender: index
        })
        this.$emit('update:sex')
        this.$emit('close')
      },
      onCancel() {
        this.$emit('close')
      }
    }
  }
  </script>
  
  <style scoped lang="less"></style>